#=====================================================================
if(__MACRO_MUST_INCLUDE)
  return()
endif()
set(__MACRO_MUST_INCLUDE TRUE)

#ONLY_USE_MODULES:设置变量只用包含公有模块处理，不需要其它全局设置
#可能会影响EWX的处理过程
# 查找cmake-ext顺序
#   1.本地工程目录
#   2.CMAKE_ROOT:cmake的安装目录
#   3.环境变量: CMAKE_EXT_ROOT
#

SET(_MUSTINCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR})
macro(MUST_INCLUDE)
    SET(PROJECT_MUST_INCLUDE TRUE CACHE INTERNAL "")
    #message(STATUS "^_^==Must Include Begin:${CMAKE_CURRENT_LIST_DIR}...")

    SET(options NO ONLY_USE_MODULES)
    SET(oneValueArgs)
    SET(multiValueArgs )
    
    cmake_parse_arguments(_MustInclude 
            "${options}" 
            "${oneValueArgs}" 
            "${multiValueArgs}" 
            ${ARGN})

    IF(_MustInclude_ONLY_USE_MODULES)
        SET(PROJECT_ONLY_USE_MODULES ON CACHE INTERNAL "" FORCE)
    ENDIF()
    #=======================Must Include=========================
    SET(_HAS_VIREMODULE FALSE)
    #message(FATAL_ERROR ${_MUSTINCLUDE_DIR})
    IF(WIN32)
        IF(EXISTS ${_MUSTINCLUDE_DIR}/cmake-ext/_VIREModules.cmake)
            include(${_MUSTINCLUDE_DIR}/cmake-ext/_VIREModules.cmake)
            SET(_HAS_VIREMODULE TRUE)
        ELSEIF(EXISTS "${CMAKE_ROOT}/../../cmake-ext/_VIREModules.cmake")
            include(${CMAKE_ROOT}/../../cmake-ext/_VIREModules.cmake)
            SET(_HAS_VIREMODULE TRUE)
        ELSEIF(EXISTS "${_MUSTINCLUDE_DIR}/_VIREModules.cmake")
            include(${_MUSTINCLUDE_DIR}/_VIREModules.cmake)
            SET(_HAS_VIREMODULE TRUE)
        ENDIF()
    ELSEIF(UNIX)
        # 可选环境变量
        set(CMAKE_EXT_ROOT_PATH $ENV{CMAKE_EXT_ROOT})
        
        IF(EXISTS ${_MUSTINCLUDE_DIR}/cmake-ext/_VIREModules.cmake)
            include(${_MUSTINCLUDE_DIR}/cmake-ext/_VIREModules.cmake)
            SET(_HAS_VIREMODULE TRUE)
        ELSEIF(EXISTS "${CMAKE_ROOT}/../../cmake-ext/_VIREModules.cmake")
            include(${CMAKE_ROOT}/../../cmake-ext/_VIREModules.cmake)
            SET(_HAS_VIREMODULE TRUE)
        ELSEIF(EXISTS "${_MUSTINCLUDE_DIR}/_VIREModules.cmake")
            include(${_MUSTINCLUDE_DIR}/_VIREModules.cmake)
            SET(_HAS_VIREMODULE TRUE)
        ELSEIF(EXISTS ${CMAKE_EXT_ROOT_PATH})
            include(${CMAKE_EXT_ROOT_PATH}/_VIREModules.cmake)
            SET(_HAS_VIREMODULE TRUE)
        ENDIF()
    ENDIF(WIN32)


    IF(NOT _HAS_VIREMODULE AND NOT ${_MustInclude_NO})
        message(FATAL_ERROR "NO VIREModules Support...It Will Get Many Error In Followed Sections...")
    ENDIF()
    #=============================================================

    #message(STATUS "^_^::Must Include End!!!")
endmacro()

